<?php

/**
 * @Author: Wang Chunsheng 2192138785@qq.com
 * @Date:   2020-03-11 17:30:12
 * @Last Modified by:   Wang Chunsheng 2192138785@qq.com
 * @Last Modified time: 2020-03-11 18:13:44
 */

use richardfan\widget\JSRegister;
use yii\helpers\Html;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $model app\modules\diandi_shop\models\DdShopAreas */

$this->title = '添加配送点';
$this->params['breadcrumbs'][] = ['label' => '配送点', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>

<ul class="nav nav-tabs">
    <li class="active">
        <?= Html::a('添加配送点', ['create'], ['class' => 'btn btn-primary']) ?>
    </li>
    <li>
        <?= Html::a('配送点管理', ['index'], ['class' => '']) ?>
    </li>
</ul>
<div class="firetech-main">
    <div class="panel panel-default">
        <div class="box-body">
            <div class="dd-shop-areas-create">

                <?= $this->render('_form', [
                    'Helper' => $Helper,
                    'model' => $model,
                ]) ?>

            </div>
        </div>
    </div>
</div>
<?php JSRegister::begin([
    'id' => 'area'
]) ?>
<script>
    //分类
    $("#classsearch-cocate_id").change(function() {
        var cocateId = $(this).val(); //获取一级目录的值
        console.log(cocateId)
        if (cocateId > 0) {
            getCourse(cocateId, 'classsearch-course_id', '选择城市'); //查询二级目录的方法
        }
    });
    $("#classsearch-course_id").change(function() {
        var cocateId = $(this).val(); //获取一级目录的值

        console.log(cocateId)
        if (cocateId > 0) {
            getCourse(cocateId, 'classsearch-course2_id', '选择地区'); //查询三级目录的方法

        }
    });


    function getCourse(cocateId, ids, initTitle) {
        var href = "<?= Url::to(['/system/index/childcate']) ?>"; //请求的地址
        $.ajax({
            "type": "post",
            "url": href,
            "data": {
                parent_id: cocateId,
                type: "course"
            }, //所需参数和类型
            success: function(d) {
                var htmls = "<option value=\"\">" + initTitle + "</option>";
                $.each(d, function(index, item) {
                    htmls += '<option value="' + item.id + '">' + item.name + '</option>';

                })
                console.log(htmls)
                $("#" + ids).html(htmls); //返回值输出
            }
        });
    }
</script>
<?php JSRegister::end(); ?>